package cn.edu.hbsi.dao;

import cn.edu.hbsi.domain.Worker;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface WorkerDao
{
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "age",property = "age"),
            @Result(column = "sex",property = "sex"),
            @Result(column = "worker_id",property = "worker_id")
    })

    //查询所有工人信息
    @Select("select * from tb_worker")
    public List<Worker> selectAllWorkers();

    //根据id和姓名查询工人信息
    @Select("select * from tb_worker where id=#{id} and name=#{name}")
    public Worker selectWorkerByIdAndName(@Param("id")Integer id,@Param("name")String name);

    //根据工号查找工人信息
    @Select("select * from tb_worker where worker_id=#{worker_id}")
    public Worker selectWorkerByWorkerId(Integer worker_id);

    //根据id查询工人
    @Select("select * from tb_worker where id=#{id}")
    public Worker selectWorkerById(Integer id);

    //插入工人信息
    @Insert("insert into tb_worker(id,name,age,sex,worker_id) values(null,#{name},#{age},#{sex},#{worker_id})")
    public Integer insertWorker(Worker worker);

    //修改工人信息
    @Update("update tb_worker set name=#{name},age=#{age},sex=#{sex} where id=#{id}")
    public Integer updateWorker(Worker worker);

    //删除工人信息
    @Delete("delete from tb_worker where id=#{id}")
    public Integer deleteWorker(Integer id);
}
